/*Name:Yifu Diao
 *Dec 8,2010
 *15600-HW9 
 * */
package edu.cmu.cs.task7.model;

import java.util.HashMap;

import com.ebay.sdk.ApiContext;
import com.ebay.sdk.ApiException;
import com.ebay.sdk.SdkException;
import com.ebay.sdk.call.GetItemCall;
import com.ebay.sdk.util.eBayUtil;
import com.ebay.soap.eBLBaseComponents.AmountType;
import com.ebay.soap.eBLBaseComponents.DetailLevelCodeType;
import com.ebay.soap.eBLBaseComponents.FeeType;
import com.ebay.soap.eBLBaseComponents.FeesType;
import com.ebay.soap.eBLBaseComponents.ItemType;

public class ReviseItemModel {
	 private HashMap params;
	 private ApiContext apiContext=new ApiContext();	 
	 
     public ReviseItemModel(ApiContext apiContext, HashMap params)  throws Exception{
    	 this.apiContext=apiContext;
    	 this.params=params; 
     }
     
     public String[] reviseItem() throws ApiException, SdkException, Exception{
    	 
    	 com.ebay.sdk.call.ReviseItemCall api = new com.ebay.sdk.call.ReviseItemCall(this.apiContext);
         ItemType item = new ItemType();
         String itemId = (String)params.get("itemid");
         item.setItemID(itemId);
         item.setTitle((String)params.get("title"));
         item.setQuantity(Integer.parseInt((String)params.get("quantity")));
         
         
         AmountType st = new AmountType();
	     st.setValue(Double.parseDouble((String)params.get("startprice")));
	     item.setStartPrice(st);
	     
	     AmountType rs = new AmountType();
	     rs.setValue(Double.parseDouble((String)params.get("reserveprice")));
	     item.setReservePrice(rs);
         
         AmountType at = new AmountType();
	     at.setValue(Double.parseDouble((String)params.get("binprice")));
	     item.setBuyItNowPrice(at);
         
         item.setDescription((String)params.get("description"));
         
         api.setItemToBeRevised(item);

         FeesType fees = api.reviseItem();

         // Display results.
         String[] results=new String[2];
         results[0]=item.getItemID().toString();
         FeeType ft = eBayUtil.findFeeByName(fees.getFee(), "ListingFee");
         results[1]=new Double(ft.getFee().getValue()).toString();         
         return results;
     }
     
}
